package com.lagou.dockerdemo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lagou.dockerdemo.entity.Student;
import com.lagou.dockerdemo.entity.Tbuser;
import com.lagou.dockerdemo.service.StudentService;
import com.lagou.dockerdemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {

    @Autowired
    private StudentService studentService;

    public StudentController(StudentService studentService) {
        this.studentService = studentService;
    }

    @GetMapping
    public List<Student> student(
    ) {
        return studentService.list();
    }

    @GetMapping("/{id}")
    public Student getOne(@PathVariable("id") String id) {
        return studentService.getById(Long.parseLong(id));
    }

    @PostMapping
    public boolean addOne(@RequestBody Student student) {
        return studentService.save(student);
    }


    @PutMapping
    public boolean updateOne(@RequestBody Student student) {
        return studentService.updateById(student);
    }

    @DeleteMapping("/{id}")
    public boolean deleteOne(@PathVariable("id") String id) {
        return studentService.removeById(id);
    }

}
